'''
Created on 22.11.2012

@author: felix_000
'''
import unittest
from game.datastructure.PentalathField import PentalathField
from game.datastructure.PlayerColor import PlayerColor
from game import GameLogic


class Test(unittest.TestCase):

    def testGetNeighbours(self):
        EXPECTED_NEIGHBOURS = [(7,8), (7,7), (8,7)]
        field = PentalathField()
        neighbours = GameLogic.getNeighbours(field, (8,8))
        self.assertEqual(len(EXPECTED_NEIGHBOURS), len(neighbours), "Expected correct length")
        for EXPECTED_NEIGHBOUR in EXPECTED_NEIGHBOURS:
            self.assertTrue(EXPECTED_NEIGHBOUR in neighbours, "Expected " + str(EXPECTED_NEIGHBOURS) + " in neighbours")

    def testGetMaxLen(self):
        field = PentalathField()
        field.place(PlayerColor.BLACK, 2, 4)
        field.place(PlayerColor.BLACK, 3, 4)
        field.place(PlayerColor.BLACK, 4, 4)
        field.place(PlayerColor.WHITE, 1, 1)
        field.place(PlayerColor.WHITE, 3, 1)
        maxLen = len(GameLogic.getMaxLen(field, PlayerColor.BLACK, 0, GameLogic.WIN_LENGTH))
        self.assertEqual(maxLen, 3, "Black should have a row of 3 stones. Has " + str(maxLen))
        
    def testIsAllowed(self):
        field = PentalathField()
        allowed = GameLogic.isAllowed(field, (4,4), PlayerColor.WHITE)
        self.assertEqual(allowed, True, "Move has to be allowed")
        


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testGetMaxLen']
    unittest.main()